package com.weharvest.edu.token;

import lombok.Data;
import lombok.Getter;

/**
 * token的三种状态
 */
@Getter
public enum TokenState {
	/**
	 * 过期
	 */
	EXPIRED(403,"token过期"),
	/**
	 * 无效(token不合法)
	 */
	INVALID(403,"token不合法"),
	/**
	 * 有效的
	 */
	VALID(200,"token有效");

	private Integer code;
	private String state;

	TokenState(Integer code, String state) {
		this.code = code;
		this.state = state;
	}
	/**
	 * 根据状态字符串获取token状态枚举对象
	 * 
	 * @param tokenState
	 * @return
	 */
	public static TokenState getTokenState(String tokenState) {
		TokenState[] states = TokenState.values();
		TokenState ts = null;
		for (TokenState state : states) {
			if (state.toString().equals(tokenState)) {
				ts = state;
				break;
			}
		}
		return ts;
	}

	public String toString() {
		return this.state;
	}

}
